//
//  DControlDefine.h
//  DFrame
//
//  Created by DaiSuke on 16/9/27.
//  Copyright © 2016年 DaiSuke. All rights reserved.
//

#ifndef DControlDefine_h
#define DControlDefine_h

// arc
#define ARC_PROP_RETAIN strong
#define ARC_RETAIN(x) (x)
#define ARC_RELEASE(x)
#define ARC_AUTORELEASE(x) (x)
#define ARC_BLOCK_COPY(x) (x)
#define ARC_BLOCK_RELEASE(x)
#define ARC_SUPER_DEALLOC()
#define ARC_AUTORELEASE_POOL_START() @autoreleasepool {
#define ARC_AUTORELEASE_POOL_END() }

// if do else do
#define HasMessageAndAlert(dic,doSomeThing) if(dic && [dic objectForKey:kMessage] != kNull){doSomeThing}

#define DicHasKeyAndDo(dic,hasKey,doSomeThing) if([dic objectForKey:hasKey] && [dic objectForKey:hasKey] != kNull){doSomeThing}

#define IfIsTrueAndDo(isTrue,doSomeThing) if((isTrue)){doSomeThing}


//单例
#define SYNTHESIZE_SINGLETON_FOR_CLASS(className)   + (className *)share { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className;\
}



// 弱引用
#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif

#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif


//打印
#ifdef  DEBUG   //DeBug版本宏

#define DLog(fmt, ...)                  NSLog((@"[Method:%s]-[Line %d]->" fmt),__PRETTY_FUNCTION__, __LINE__,##__VA_ARGS__)
#define DLogSize(_size)                 DLog(@"CGSize:%@", NSStringFromCGSize(_size))
#define DLogRect(_rect)                 DLog(@"NSRect:%@",NSStringFromCGRect(_rect))
#define DLogPoint(_point)               DLog(@"NSPoint:%@",NSStringFromCGPoint(_point))
#define DLogEdgeInsets(_edgeInsets)     DLog(@"UIEdgeInsets:%@",NSStringFromUIEdgeInsets(_edgeInsets))
#define DLogOffset(_Offset)             DLog(@"UIOffset:%@",NSStringFromUIOffset(_Offset))
#define DLogTransform(_Transform)       DLog(@"CGAffineTransform:%@",NSStringFromCGAffineTransform(_Transform))
#define DLogSelector                    DLog(@"Selector:%@",NSStringFromSelector(_cmd))
#define DLogClass(_ClassObject)         DLog(@"Class:%@",NSStringFromClass([_ClassObject class]))


#else           //Release版本宏（发布版本）

#define DLog(fmt, ...)
#define DLogSize(_size)
#define DLogRect(_rect)
#define DLogPoint(_point)
#define DLogEdgeInsets(_edgeInsets)
#define DLogOffset(_Offset)
#define DLogTransform(_Transform)
#define DLogSelector
#define DLogClass(_ClassObject)
#endif


#define DelegateHasMethorAndDo(delegate,methor,callMethor) if(delegate && [delegate respondsToSelector:@selector(methor)]){ callMethor }

#define DelegateHasMethorAndDoOrLog(delegate,methor,callMethor) if(delegate && [delegate respondsToSelector:@selector(methor)]){ callMethor }else{DLog(@"未实现%@代理方法",NSStringFromSelector(@selector(methor)));}


#define kSuccessHttp        @"0x00000000"
#define kAccountCancel      @"0x00000001"
#define HTTPSTATECODESUCCESS [[dic objectForKey:kStateCode] isEqualToString:kSuccessHttp]
#define RESPONSESUCCESS [dic objectForKey:kParamData] && [dic objectForKey:kParamData] != kNull

#define ExistActionDo(a,b) if((a)){b;}
#define ExistStringGet(str) (str).length > 0?(str):@""



#endif /* DControlDefine_h */
